/*
 *  Copyright (C) 2011 glauco
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.annotation.util;

import org.balisunrise.annotation.EventType;
import org.balisunrise.annotation.VisualActionTarget;
import org.balisunrise.common.EntityField;
import org.balisunrise.common.VisualEntity;

/**
 *
 * @author glauco
 */
public class NameUtil {

    private static final String separetor = "_";
    private static final String sharp = "#";

    public static String buildName(VisualEntity ve){

        String name = null;

        name = ve.getEntityClass().getName() +
                separetor +
                ve.getVisualEntityType().toString() +
                separetor +
                ve.getAlias();

        return name;
    }

    public static String buildName(EntityField ef){

        String name = null;

        name = ef.getEntityClass().getName() +
                sharp +
                ef.getFieldName() +
                separetor +
                ef.getEntityFieldType().toString() +
                separetor +
                ef.getAlias();
        
        return name;
    }

    public static String buildName(ActionUtilities au){

        String name = null;

        name = au.actionMapClass.getName() +
                sharp +
                au.method.getName();

        if (au.actionKind == ActionUtilities.VISUAL_ACTION){
            name += "_VISUAL_ACTION";
            for (VisualActionTarget t : au.visualActionTargets) {
                name += separetor + t.toString();
            }
        } else {
            name += "_ACTION";
            for (EventType t : au.actionTargets) {
                name += separetor + t.toString();
            }
        }

        for (String a : au.alias) {
            name += separetor + a;
        }

        return name;
    }
}
